package fr.mmteam.selenium.ext;

import org.openqa.selenium.support.ui.ExpectedCondition;

import org.openqa.selenium.support.ui.WebDriverWait;

import java.util.List;
import java.util.Set;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class WebDriverExtImpl implements WebDriverExt {

    /**
     * Logger for this class.
     */
    private final Logger logger = LoggerFactory.getLogger(WebDriverExtImpl.class);

    private WebDriver driver;

    public WebDriverExtImpl(final WebDriver driver) {
        this.driver = driver;
    }

    public WebDriver getWrappedDriver() {
        return driver;
    }

    public void get(String url) {
        getWrappedDriver().get(url);
    }

    public String getCurrentUrl() {
        return getWrappedDriver().getCurrentUrl();
    }

    public String getTitle() {
        return getWrappedDriver().getTitle();
    }

    public List<WebElement> findElements(By by) {
        return getWrappedDriver().findElements(by);
    }

    public WebElement findElement(By by) {
        return getWrappedDriver().findElement(by);
    }

    public String getPageSource() {
        return getWrappedDriver().getPageSource();
    }

    public void close() {
        getWrappedDriver().close();
    }

    public void quit() {
        getWrappedDriver().quit();
    }

    public Set<String> getWindowHandles() {
        return getWrappedDriver().getWindowHandles();
    }

    public String getWindowHandle() {
        return getWrappedDriver().getWindowHandle();
    }

    public TargetLocator switchTo() {
        return getWrappedDriver().switchTo();
    }

    public Navigation navigate() {
        return getWrappedDriver().navigate();
    }

    public Options manage() {
        return getWrappedDriver().manage();
    }

    public WebElement waitForElement(final By by, int timeOutInSeconds) {
        return (new WebDriverWait(getWrappedDriver(), timeOutInSeconds)).until(new ExpectedCondition<WebElement>() {

            @Override
            public WebElement apply(WebDriver d) {
                return d.findElement(by);
            }
        });
    }

}
